package com.nulldev.util.graphics.renderIt.renderer.swing.smoothCanvas;

import java.awt.AWTEvent;
import java.awt.AWTException;
import java.awt.BufferCapabilities;
import java.awt.BufferCapabilities.FlipContents;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.GraphicsConfiguration;
import java.awt.Image;
import java.awt.Panel;
import java.awt.Point;
import java.awt.event.PaintEvent;
import java.awt.image.ColorModel;
import java.awt.image.ImageObserver;
import java.awt.image.ImageProducer;
import java.awt.image.VolatileImage;
import java.awt.peer.ComponentPeer;
import java.awt.peer.ContainerPeer;

import javax.swing.JPanel;

import sun.awt.CausedFocusEvent.Cause;
import sun.java2d.pipe.Region;

public class ComponentPeerTL implements ComponentPeer {

	private final ComponentPeer peer;
	private final Panel awt_sauce;
	private final JPanel swing_sauce;

	public ComponentPeerTL(final ComponentPeer peer, final Panel panel) {
		this.peer = peer;
		this.awt_sauce = panel;
		this.swing_sauce = null;
	}

	public ComponentPeerTL(final ComponentPeer peer, final JPanel panel) {
		this.peer = peer;
		this.swing_sauce = panel;
		this.awt_sauce = null;
	}

	@Override
	public boolean isObscured() {
		return this.peer.isObscured();
	}

	@Override
	public boolean canDetermineObscurity() {
		return this.peer.canDetermineObscurity();
	}

	@Override
	public void setVisible(boolean v) {
		this.peer.setVisible(v);
	}

	@Override
	public void setEnabled(boolean e) {
		this.peer.setEnabled(e);
	}

	@Override
	public void paint(Graphics g) {
		this.peer.paint(g);
	}

	@Override
	public void print(Graphics g) {
		this.peer.print(g);
	}

	@Override
	public void setBounds(int x, int y, int width, int height, int op) {
		this.peer.setBounds(x, y, width, height, op);
	}

	@Override
	public void handleEvent(AWTEvent e) {
		this.peer.handleEvent(e);
	}

	@Override
	public void coalescePaintEvent(PaintEvent e) {
		this.peer.coalescePaintEvent(e);
	}

	@Override
	public Point getLocationOnScreen() {
		return this.peer.getLocationOnScreen();
	}

	@Override
	public Dimension getPreferredSize() {
		if (this.peer == null)
			return new Dimension(0, 0);
		return this.peer.getPreferredSize();
	}

	@Override
	public Dimension getMinimumSize() {
		return this.peer.getMinimumSize();
	}

	@Override
	public ColorModel getColorModel() {
		return this.peer.getColorModel();
	}

	@Override
	public Graphics getGraphics() {
		if (this.awt_sauce != null)
			return this.awt_sauce.getGraphics();
		return this.swing_sauce.getGraphics();
	}

	@Override
	public FontMetrics getFontMetrics(Font font) {
		return this.peer.getFontMetrics(font);
	}

	@Override
	public void dispose() {
		this.peer.dispose();
	}

	@Override
	public void setForeground(Color c) {
		this.peer.setForeground(c);
	}

	@Override
	public void setBackground(Color c) {
		this.peer.setBackground(c);
	}

	@Override
	public void setFont(Font f) {
		this.peer.setFont(f);
	}

	@Override
	public void updateCursorImmediately() {
		this.peer.updateCursorImmediately();
	}

	@Override
	public boolean requestFocus(Component lightweightChild, boolean temporary, boolean focusedWindowChangeAllowed, long time, Cause cause) {
		return this.peer.requestFocus(lightweightChild, temporary, focusedWindowChangeAllowed, time, cause);
	}

	@Override
	public boolean isFocusable() {
		return this.peer.isFocusable();
	}

	@Override
	public Image createImage(ImageProducer producer) {
		return this.peer.createImage(producer);
	}

	@Override
	public Image createImage(int width, int height) {
		return this.peer.createImage(width, height);
	}

	@Override
	public VolatileImage createVolatileImage(int width, int height) {
		return this.peer.createVolatileImage(width, height);
	}

	@Override
	public boolean prepareImage(Image img, int w, int h, ImageObserver o) {
		return this.peer.prepareImage(img, w, h, o);
	}

	@Override
	public int checkImage(Image img, int w, int h, ImageObserver o) {
		return this.peer.checkImage(img, w, h, o);
	}

	@Override
	public GraphicsConfiguration getGraphicsConfiguration() {
		if (this.awt_sauce != null)
			return this.awt_sauce.getGraphicsConfiguration();
		return this.swing_sauce.getGraphicsConfiguration();
	}

	@Override
	public boolean handlesWheelScrolling() {
		return this.peer.handlesWheelScrolling();
	}

	@Override
	public void createBuffers(int numBuffers, BufferCapabilities caps) throws AWTException {
		this.peer.createBuffers(numBuffers, caps);
	}

	@Override
	public Image getBackBuffer() {
		return this.peer.getBackBuffer();
	}

	@Override
	public void flip(int x1, int y1, int x2, int y2, FlipContents flipAction) {
		this.peer.flip(x1, y1, x2, y2, flipAction);
	}

	@Override
	public void destroyBuffers() {
		this.peer.destroyBuffers();
	}

	@Override
	public void reparent(ContainerPeer newContainer) {
		this.peer.reparent(newContainer);
	}

	@Override
	public boolean isReparentSupported() {
		return this.peer.isReparentSupported();
	}

	@Override
	public void layout() {
		this.peer.layout();
	}

	@Override
	public void applyShape(Region shape) {
		this.peer.applyShape(shape);
	}

	@Override
	public void setZOrder(ComponentPeer above) {
		this.peer.setZOrder(above);
	}

	@Override
	public boolean updateGraphicsData(final GraphicsConfiguration gc) {
		if (gc == null)
			return false;
		if (this.peer == null)
			return false;
		return this.peer.updateGraphicsData(gc);
	}

	public ComponentPeer getTruePeer() {
		return this.peer;
	}
}
